import router from '@/router/index'
import store from '@/store/index'
import Nprogress from 'nprogress'
import 'nprogress/nprogress.css'
// 导航守卫
router.beforeEach((to, from, next) => {
  Nprogress.start()
  const token = store.state.user.token
  const whitePages = ['/login', '/404']
  if (token) {
    if (to.path.toLowerCase() === '/login') {
      next('/dashboard')
    } else {
      next()
    }
  } else {
    if (whitePages.includes(to.path.toLowerCase())) {
      next()
    } else {
      next('/login')
    }
  }
  Nprogress.done()
})
router.afterEach(() => {
  Nprogress.done()
})
